package com.hmy.infrastructure.client.sms;

import com.hmy.ccp.common.result.FeignResult;
import com.hmy.ccp.common.result.Results;
import com.hmy.ccp.error.annotations.HmyFeignController;
import com.hmy.common.exception.ClientException;
import com.hmy.infrastructure.api.bo.request.sms.CheckVerificationCodeRequest;
import com.hmy.infrastructure.api.bo.request.sms.SendVerificationCodeRequest;
import com.hmy.infrastructure.api.bo.request.sms.SmsRequest;
import com.hmy.infrastructure.bo.response.CheckVerificationCodeResponse;
import com.hmy.infrastructure.service.SmsService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@Api(tags = "SMS短信业务Client")
@Validated
@RestController("internalSmsController")
@Slf4j
@HmyFeignController
public class SmsClientController {

    @Resource
    private SmsService smsService;


    @PostMapping("/feign/sms/send")
    public FeignResult<Boolean> send(@RequestBody SmsRequest smsRequest) throws ClientException {
        smsService.sendSms(smsRequest);
        return Results.newSuccessResult(Boolean.TRUE);
    }

    /**
     * 发送验证码
     *
     * @param sendVerificationCodeRequest 发送验证码参数
     * @return 是否发送成功
     */
    @PostMapping("/feign/sms/sendVerificationCode")
    public FeignResult<Boolean> sendVerificationCode(@RequestBody @Validated SendVerificationCodeRequest sendVerificationCodeRequest){
        return Results.newSuccessResult(smsService.sendVerificationCode(sendVerificationCodeRequest));
    }

    /**
     * 校验验证码
     *
     * @param checkVerificationCodeRequest 校验验证码参数
     * @return 校验结果
     */
    @PostMapping("/feign/sms/checkVerificationCode")
    public FeignResult<CheckVerificationCodeResponse> checkVerificationCode(@RequestBody @Validated CheckVerificationCodeRequest checkVerificationCodeRequest){
        return Results.newSuccessResult(smsService.checkVerificationCode(checkVerificationCodeRequest));
    }
}
